#include "Bullet.h"
#include "Player.h"


Bullet::Bullet(QGraphicsItem *parent, Player* _owner, const QPointF& start_pos, const QPointF& start_vel) :
    owner(_owner)
{
    velocity = start_vel;
    owner = _owner;
    radius = 5;
    setRect(0, 0, 2*radius, 2*radius);
    setPos(start_pos);
    setParentItem(parent);
    timer = new QTime;
    timer->start();

    img = new QImage;
    type = owner->type;

    if (owner->type == 1)
        img->load("../shared/player1.png");
    else if (owner->type == 2)
        img->load("../shared/player3.png");
    else if (owner->type == 3)
        img->load("../shared/player2.png");

    img->scaled(2*radius, 2*radius);
}


void Bullet::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
    QRectF r;
    r.setRect(0, 0, 2*radius, 2*radius);
    painter->drawImage(r, *img);
}


Bullet::~Bullet()
{
    delete timer;
    delete img;
}
